package com.erp.user.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.Exchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description: 分销 服务交换机 队列设置
 * @Author: j.zh
 * @Date: 2024/5/2
 * @Version: 4.0.0
**/
@Configuration
public class DistributionMQConfig {

    /**
     * 分销交换机
     * TopicExchange
     * 创建topic类型的交换机
     * @return
     */
    @Bean
    public Exchange distributionEventExchange() {
        return new TopicExchange("distribution-event-exchange", true, false);
    }

    /**
     * 初始化BOM队列-销售系统（ERP、代理、市级合伙人）
     * @return
     */
    @Bean
    public Queue saleSystemQueue() {
        Queue queue = new Queue("distribution.sale.system.queue", true, false, false);
        return queue;
    }

    /**
     * 路由和交换机进行绑定 设置路由key
     * String destination, 目的地（队列名或者交换机名字）
     * DestinationType destinationType, 目的地类型（Queue、Exhcange）
     * String exchange,
     * String routingKey,
     * Map<String, Object> arguments
     */
    @Bean
    public Binding saleSystemBinding() {
        // 提成分销
        return new Binding("distribution.sale.system.queue",
                Binding.DestinationType.QUEUE,
                "distribution-event-exchange",
                "distribution.sale.system.divide",
                null);
    }

}

